package org.platform.lwc.redis.factory.redission;

import org.platform.lwc.redis.utils.ConvertUtil;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;
import java.util.List;

public class ClusterRedissonClient implements IRedissonClient {
    @Override
    public RedissonClient getRedissonClient(RedisProperties redisProperties) {
        // 集群配置
        Method clusterMethod = ReflectionUtils.findMethod(RedisProperties.class, "getCluster");
        Object clusterObject = ReflectionUtils.invokeMethod(clusterMethod, redisProperties);
        Method nodesMethod = ReflectionUtils.findMethod(clusterObject.getClass(), "getNodes");
        List<String> nodesObject = (List) ReflectionUtils.invokeMethod(nodesMethod, clusterObject);
        String[] nodes = ConvertUtil.convert(nodesObject);
        Config config = new Config();
        config.useClusterServers()
                .addNodeAddress(nodes)
                .setConnectTimeout(ConvertUtil.getConnectTimeout(redisProperties))
                .setPassword(redisProperties.getPassword());


        return null;
    }
}
